<?php

//header("content-type:application/json");
include 'config.php';
	$con = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME) or die ("Could not execute query");
	$query = "SELECT * FROM d3 WHERE userid = 1";
	//echo $query;
	$result = mysqli_query($con,$query) or die ("Could not get the user lex information");
	$numfields = mysqli_num_fields($result);
	$x = 0;
	$numrows = mysqli_num_rows($result);
	
	while ($row = mysqli_fetch_array($result))
    {
    	$lextitle = $row['title'];
    	$lexcontext = $row['context'] ;	
	    	$lexid = $row['id'] ;
		    	$lexsource = $row['source'] ;
			    	$lexuserid = $row['userid'] ;
  }
   
  //start the json 
   echo '{"name":'.$lexuserid.',';
   echo '<br/>';
   echo ' "children": [';
   echo '<br/>';


   //get the contexts
$query2 = "SELECT * FROM d3 WHERE userid = 1";
$result2 = mysqli_query($con,$query2) or die ("Could not get the user lex information");
$numrows2 = mysqli_num_rows($result2);
	while ($rows2 = mysqli_fetch_array($result2))
    {
    	$name = '"name:" ';
	$json = $name . json_encode($rows2['context']) ;
 	echo "<br>";
	print($json);

	// echo '{"name":'. $rows2['context'] .',';
	// echo '<br/>';
	// echo '{"name":'. $rows2['source'] .',';
	// echo '<br/>';
	// echo '"size": 3000},';
	// echo '<br/>';
	
	}	
  echo ']';
 echo ']';

	
	

   // echo '{"name":'.$lexuserid.',';
   // echo ' "children": [';
   // echo ' {';
			// echo '"name": "Home context",';
			// echo '"children": [';
			// echo '	{';
			// echo '		"name":'. $lexsource .',';
			// echo '		"size": 3000';
			// echo '	}, {';
			// echo '		"name":  $source ,';
			// echo '		"size": 3000';
			// echo '	}, {';
			// echo '		"name": $source ,';
			// echo '		"size": 3000';
			// echo '	}';
			// echo ']';
// echo ' }, {';
// echo ' 			"name": "node4", //context 2';
// echo ' 			"size": 5000';
// echo ' 		}, {';
// echo ' 			"name": "node5", //context3';
// echo ' 			"size": 100000';
// echo ' 		}';
// echo ' 	]';
// echo ' }';

//print_r(json_encode($data));	



?>

